package com.hsm8;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Test1 {
    public static void main(String[] args) {
        /*
        增:   put(K key,V value)
        删:   clear() remove()
        改
        查:   entrySet()返回此映射中包含的映射关系的Set试图
              get(Object o)
              keySet()
              size()
              values()
        判断： containsKey(Object key) containsValue(Object value)
              equals(Object o)
              isEmpty()
        */
        //创建一个实现类
        Map<String,Integer> map = new HashMap<>();
        map.put("hsm",806521);
        System.out.println(map.put("cy", 535172));
        System.out.println(map.put("cy", 111111));
        map.put("hdsa",655454);
        map.put("ds",541145);
        System.out.println(map.size());
        System.out.println(map);
        System.out.println("----------");
        Set<String> set1 = map.keySet();
        for(String s: set1){
            System.out.println(s);
        }
        System.out.println("-----------");
        Collection<Integer> set2 = map.values();
        for(Integer i:set2){
            System.out.println(i);
        }
        System.out.println("-----------");
        Set<String> set3 = map.keySet();
        for(String s: set3){
            System.out.println(map.get(s));
        }
        System.out.println("-----------");
        //Set中的元素是Entry接口的具体实现类，而实现类就是将键和值封装了起来
        Set<Map.Entry<String, Integer>> entries =  map.entrySet();
        for(Map.Entry<String, Integer> e:entries){
            System.out.println(e.getKey());
            System.out.println("----");
            System.out.println(e.getValue());
        }
    }
}
